<?php
// +----------------------------------------------------------------------
// | OneThink [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013 http://www.onethink.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: 麦当苗儿 <zuojiazi@vip.qq.com> <http://www.zjzit.cn>
// +----------------------------------------------------------------------
namespace Admin\Service;

class ImageSheetService{
	
    /**
     * 保存图片和谱单的关系
     * @return unknown
     */
    public function save($image_ids, $sheet_id){

        $Model = D('ImageSheet');
        //step-0: 先删除历史数据
        /*$Model->where(array('sheet_id'=>$sheet_id))->save(array('is_delete' => 1));*/
        
        //step-1: 组织图片和谱单的关系
        $image_sheet = array();
        foreach ($image_ids as $key=>$image_id) {
            $image_sheet[] = array(
                'sheet_id' => $sheet_id,
                'image_id' => $image_id,
                'creator'  => 2
            );
        }
        
        //step-2: 批量保存图片和谱单的关系
        return $Model->addAll($image_sheet);
        
	}
	
	public function delete($image_id, $sheet_id) {
	    $map = array(
	        "image_id" =>$image_id,
	        "sheet_id" => $sheet_id
	    );
	    $data = array(
	        'is_delete'=>1,
            'update_time' => date('Y-m-d H:i:s', time())
        );
	    return M('ImageSheet')->where($map)->save($data);
	}
	
}